<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/layouts/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>新增自定义字段</title>
</head>
<body>
<div class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-dict-add">
		<input type="hidden"  name="categoryId"  id="categoryId"  value="${fieldCategory.categoryId }">
		<input type="hidden"  name="id"  id="id"  value="${fieldCategory.id }">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>英文名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="${fieldCategory.enName }" placeholder="请输入英文名称" id="enName" name="enName">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>展示名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="${fieldCategory.showName }" placeholder="请输入字段的展示名称" id="showName" name="showName">
			</div>
		</div>
		<div class="row cl" >
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>字段类型：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select class="select" size="1" name="fieldId"  id="fieldId">
					<c:forEach items="${fns:getDictList('form_field')}"  var="field">
						<option value="${field.id }"   data-value="${field.value }"   <c:if test="${fieldCategory.fieldId == field.id  }">selected</c:if>   >${field.label }</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="row cl"   id="defaultShow"  <c:if  test="${fieldCategory.defaultValue == null || fieldCategory.defaultValue ==''}">style="display: none;"</c:if>>
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>默认值：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="defaultValue"  id="defaultValue"  cols="" rows="" class="textarea"  placeholder="请输入标签值"  >${fieldCategory.defaultValue }</textarea>
				<p class="textarea-numberbar"><em class="textarea-length">多个值之前请用英文逗号间隔</p>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button  class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
				<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
	</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${ctxLib }/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${ctxLib }/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${ctxStatic}/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="${ctxStatic}/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${ctxLib }/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="${ctxLib }/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="${ctxLib }/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="${ctxLib }/shopUtil.js"></script>
<script type="text/javascript">
$(function(){
	$("#form-dict-add").validate({
		rules:{
			enName:{
				required:true
			},
			showName:{
				required:true
			},
			fieldId:{
				required:true
			}
		},
		messages: {
			  enName: {
		        	required: "请输入英文名称"
		      },
		      showName: {
		        	required: "请输入字段名称"
		      },
		      fieldId:{
		    	  required:"请选择字段类型"
		      }
	    },
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
				var formData = ShopUtil.formToJSON();
				var select = $("#fieldId").find("option:selected");
				formData.fieldName = select.text();
				formData.labelValue = select.data("value");
				if((formData.labelValue == "select" || formData.labelValue == "radio" || formData.labelValue=="checkbox") 
					&& ($('#defaultValue').val()== null || $('#defaultValue').val() == "")){
					layer.alert("该选择必须输入默认值");
					return;
				}
				$.ajax({
                    type: 'POST',
                    url: '${ctx}/fieldCategory/edit',
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify(formData),
                    dataType: 'json',
                    success: function (data) {
                        if (data.success) {
                            layer.alert('编辑成功', {
                            	  closeBtn: 0
                            }, function(){
                            	window.parent.location.reload();
                            	var index = parent.layer.getFrameIndex(window.name);
                            	parent.layer.close(index);
                           	});
                        } else {
                            layer.alert(data.message);
                        }
                    }
                });
			}
		});
	$("#fieldId").change(function(){
		var checkText=$(this).find("option:selected").attr("data-value");
		console.log(checkText);
		if(checkText == "select" || checkText == "radio" || checkText == "checkbox"){
			$("#defaultShow").show();
		}else{
			$("#defaultShow").hide();
		}
	});
	//自定义正则表达示验证方法  
    $.validator.addMethod("checkSelect",function(value,element,params){  
            var checkQQ = /^[.\n]+$/;  
            return this.optional(element)||(checkQQ.test(value));  
        },"*请选择字段类型！");
});	
</script>
</body>
</html>